/**
 * 
 */
package edu.sjtu.seda.log;

import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author john.zhu
 * 
 */
public class LogService {
	private static final String logPattern = "{0}[{1}][{2}][{3}] {4}";
	private Class<?> clazz;

	// public LogService(){
	//
	// }

	public LogService(Class<?> clazz) {
		this.clazz = clazz;
	}

	public void info(String msg) {
		System.out.println(MessageFormat.format(logPattern, toDate(), "INFO",
				Thread.currentThread().getName(), clazz.getSimpleName(), msg));
	}

	public void info(String pattern, String... msg) {
		System.out.println(MessageFormat.format(logPattern, toDate(), "INFO",
				Thread.currentThread().getName(), clazz.getSimpleName(),
				MessageFormat.format(pattern, msg)));
	}

	public void error(String msg) {
		System.err.println(MessageFormat.format(logPattern, toDate(), "ERROR",
				Thread.currentThread().getName(), clazz.getSimpleName(), msg));
	}

	public void error(String pattern, String... msg) {
		System.err.println(MessageFormat.format(logPattern, toDate(), "ERROR",
				Thread.currentThread().getName(), clazz.getSimpleName(),
				MessageFormat.format(pattern, msg)));
	}

	public void debug(String msg) {
		System.out.println(MessageFormat.format(logPattern, toDate(), "DEBUG",
				Thread.currentThread().getName(), clazz.getSimpleName(), msg));
	}

	public void debug(String pattern, String... msg) {
		System.out.println(MessageFormat.format(logPattern, toDate(), "DEBUG",
				Thread.currentThread().getName(), clazz.getSimpleName(),
				MessageFormat.format(pattern, msg)));
	}

	private String toDate() {
		Date date = new Date();
		return new SimpleDateFormat("MM/dd/yy HH:mm:ss.SSS").format(date);
	}
}
